package com.example.studentportrait.controller.admin;

import com.example.studentportrait.domain.ResponseResult;
import com.example.studentportrait.domain.entity.School;
import com.example.studentportrait.service.SchoolService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

@RestController
@RequestMapping("/admin")
public class SchoolController {

    @Autowired
    private SchoolService schoolService;

    /**
     * 新增学校
     * @param school
     * @return
     */
    @PostMapping("/addSchool")
    public ResponseResult addSchool(@RequestBody School school){
        return schoolService.addSchool(school);
    }

    /**
     * 编辑学校
     * @param school
     * @return
     */
    @PutMapping("/updateSchool")
    public ResponseResult updateSchool(@RequestBody School school){
        return schoolService.updateSchool(school);
    }

    /**
     * 删除学校
     * @param id
     * @return
     */
    @DeleteMapping("/deleteSchool/{id}")
    public ResponseResult deleteSchool(@PathVariable("id") Long id){
        return schoolService.deleteSchool(id);
    }

    /**
     * 查询学校
     * @param pageNum
     * @param pageSize
     * @param school
     * @return
     */
    @GetMapping("/schoolList")
    public ResponseResult schoolList(Integer pageNum,Integer pageSize,School school){
        return schoolService.schoolList(pageNum,pageSize,school);
    }

    /**
     * 批量删除学校
     * @param ids
     * @return
     */
    @DeleteMapping("/deleteSchoolList")
    public ResponseResult deleteSchoolList(@RequestBody List<Long> ids){
        return schoolService.deleteSchoolList(ids);
    }

    /**
     * 通过文件导入学校
     * @param file
     * @return
     */
    @PostMapping("/insertSchoolListByExcel")
    public ResponseResult insertSchoolListByExcel(@RequestParam(value = "file", required = true) MultipartFile file) {
        return schoolService.insertSchoolListByExcel(file);
    }
}
